@font-face {
    font-family: 'ui-font';
    font-weight: normal;
    font-style: normal;
    src: url('merriweather/MerriweatherSans-Light.ttf');
}
@font-face {
    font-family: 'ui-font';
    font-weight: bold;
    font-style: normal;
    src: url('merriweather/MerriweatherSans-Bold.ttf');
}
@font-face {
    font-family: 'ui-font';
    font-weight: normal;
    font-style: italic;
    src: url('merriweather/MerriweatherSans-Italic.ttf');
}
@font-face {
    font-family: 'ui-font';
    font-weight: bold;
    font-style: italic;
    src: url('merriweather/MerriweatherSans-BoldItalic.ttf');
}

@font-face {
    font-family: 'ui-font-serif';
    font-weight: normal;
    font-style: normal;
    src: url('merriweather/Merriweather-Light.ttf');
}
@font-face {
    font-family: 'ui-font-serif';
    font-weight: bold;
    font-style: normal;
    src: url('merriweather/Merriweather-Bold.ttf');
}
@font-face {
    font-family: 'ui-font-serif';
    font-weight: normal;
    font-style: italic;
    src: url('merriweather/Merriweather-Italic.ttf');
}
@font-face {
    font-family: 'ui-font-serif';
    font-weight: bold;
    font-style: italic;
    src: url('merriweather/Merriweather-BoldItalic.ttf');
}


* {
    box-sizing: border-box;
}

html {
    --bright-white: #FFF;
    --paper-white: #F5F5F5;

    --ink-black: #2A2A2A;
    --dark-grey: #4A4A4A;
    --medium-grey: #777;
    --light-grey: #E0E0E0;
    --bright-grey: #ECECEC;

    --accent: rgb(255 106 0);

    @media (prefers-color-scheme: dark) {
        --bright-white: #111;
        --paper-white: #1F1F1F;

        --ink-black: #CCC;
        --dark-grey: #DDD;
        --medium-grey: #808080;
        --light-grey: #333;
        --bright-grey: #2A2A2A;
    }

    height: 100%;
    min-height: 100%;
    font-family: 'ui-font', sans-serif;
    font-weight: normal;
    font-size: 14px;
    line-height: 20px;
    background: var(--paper-white);
}

body {
    display: flex;
    height: 100%;
    min-height: 100%;
    background: var(--paper-white);
    color: var(--ink-black);
}
h1 {
    margin: 0;
    padding: .25em 0 0 0;
    font-weight: bold;
    font-size: 14px;
}
h2 {
    margin: 0;
    padding: 0;
    font-weight: normal;
    font-size: 14px;
}
p {
    padding: 0;
}
a,
a:link,
a:visited,
a:hover,
a:active {
    text-decoration: none;
    color: inherit;
}
small {
    font-size: 10px;
}
[type='checkbox'] {
    margin-right: 1ex;
}

.screenreader-only {
    width: 1px;
    height: 1px;
    position: absolute;
    top: -999px;
    left: -999px;
    overflow:hidden
}

.no-smooth {
    -webkit-font-smoothing: none;
}

.octicon {
    fill: currentColor;
}

.main-wrapper {
    width: 28em;
    height: 100%;
    max-height: 100%;
    float: left;
    position: relative;
    z-index: 2;
    overflow: hidden;
}

.codemirror-wrapper {
    flex: 1;
    position: relative;
    margin: 6px;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 0 3px rgba(0,0,0,0.5);

    ~ .codemirror-wrapper {
        margin-left: 0;
    }

    &.clone .CodeMirror {
        /* freeze the cloned codemirror instance because it's dead and scrolls weird */
        pointer-events: none;
        &::after {
            content: '';
            display: block;
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            z-index: 1;
        }
        * {
            overflow: hidden !important;
        }
    }
}

.info-wrapper {
    position: absolute;
    bottom: 1rem;
    right: 2rem;
    left: 2rem;
    z-index: 1;
    padding: 1em 1.4em;
    font-size: 10px;
    border: 1px solid var(--light-grey);
    border-radius: 6px;
    background: var(--bright-grey);
    color: var(--dark-grey);

    @media screen and (max-width: 56em) {
        bottom: 2rem;
    }
    @media screen and (max-height: 24em)  {
        display: none;
    }

    a:hover {
        color: var(--ink-black);
        text-decoration: underline;
    }
    p {
        line-height: 14px;
    }
    p:empty {
        display: none;
    }
    p.variants::before {
        content: 'Variants: ';
        font-style: italic;
    }
    h2::after {
        content: attr(data-license);
        margin-left: 1ex;
        font-size: 8px;
        color: var(--medium-grey);
        text-transform: uppercase;
    }

    .text-button {
        position: absolute;
        top: 1em;
        right: 1.4em;

        @media screen and (max-width: 56em) {
            display: none;
        }
    }
}
main {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}
section {
    flex: 0;
    flex-shrink: 0;
}
section#filters,
section.config {
    display: grid;
    grid-column-gap: 4px;
    grid-row-gap: 4px;
    grid-row-gap: 4px;
    grid-template-columns: auto auto auto auto;
    padding: 8px;
    font-size: 10px;
    border: 1px solid var(--light-grey);
    border-radius: 6px;
    background: var(--bright-grey);
}

section#filters {
    align-items: stretch;
    grid-template-columns: auto auto auto auto auto;
    margin: 6px 0 2px 4px;

    @media screen and (max-width: 56em) {
        margin-right: 4px;
    }
}
section#filters input,
section#filters select {
    width: 100%;
    margin: 0;
}
section#filters > div {
    display: flex;
}

section.config {
    margin: 2px 0 6px 4px;

    @media screen and (max-width: 56em) {
        margin-right: 4px;
    }
}
section.config > * {
    text-align: center;
    padding: 0;
    white-space: nowrap;
}
section.select-list {
    flex: 1;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--paper-white);

    &:focus {
        outline: none;
    }
    > * {
        overflow: hidden;
    }
    [data-style='serif'] .name {
        font-family: 'ui-font-serif', serif;
    }
    .entry {
        position: relative;
        padding: 8px 12px;
        z-index: 0;
    }
    .entry:has(a:hover)::before {
        transition: background .2s ease-in-out, left .1s ease-in-out, right .1s ease-in-out;
    }
    .entry:not(:first-child)::before {
        content: '';
        display: block;
        position: absolute;
        top: 0;
        left: 6px;
        right: 6px;
        border-top: 1px solid var(--light-grey);
        pointer-events: none;
        z-index: -1;
    }
    .entry:has(a:hover)::before,
    .entry.active::before {
        content: '';
        display: block;
        position: absolute;
        top: 0;
        bottom: 0;
        right: 4px;
        left: 4px;
        border: 1px solid var(--light-grey);
        border-radius: 3px;
        pointer-events: none;
        z-index: -1;
        background: var(--bright-white);
    }
    .entry:has(a:hover) + .entry:not(:first-child)::before,
    .entry.active + .entry:not(:first-child)::before {
        border-top: none;
    }
    .entry > a {
        display: block;
        flex: 1;
    }
    .entry.filtered-out {
        display: none;
    }
    a[data-value] {
        display: block;
        width: 66.67%;
        position: relative;
        overflow: hidden;
    }
    .entry.active .name {
        font-weight: bold;
    }
    .entry.is-new .name::after {
        content: "new";
        display: inline-block;
        font-weight: normal;
        font-family: 'ui-font', sans-serif;
        font-size: 10px;
        line-height: 1;
        color: var(--medium-grey);
        border-radius: 3px;
        border: 1px solid currentColor;
        margin-left: 1em;
        padding: 2px 4px;
    }
    a.website {
        position: absolute;
        top: 6px;
        right: 32px;
        padding: 0 4px;
        font-size: 10px;
        color: var(--medium-grey);
        transition: all .2s ease-in-out;

        svg {
            position: relative;
            top: 2px;
        }
        span {
            display: inline-block;
            padding-right: 1ex;
            opacity: 0;
            transition: opacity .2s ease-in-out;
        }
        &:hover span {
            opacity: 1;
        }
    }
    a.favoritelink {
        position: absolute;
        top: 8px;
        right: 8px;
        color: var(--medium-grey);
        cursor: pointer;
    }
    .entry:not(.pinned) a.favoritelink svg {
        fill: transparent;
        stroke: currentColor;
        stroke-width: 1;
    }
    .entry:hover a.website,
    .entry:hover a.favoritelink {
        color: var(--dark-grey);
    }
    .entry:hover a.favoritelink:hover,
    a.favoritelink:hover {
        color: var(--ink-black);
    }
    .entry.active a.website,
    .entry.active a.favoritelink {
        color: var(--dark-grey);
    }
    .entry a.website:hover,
    .entry.pinned a.favoritelink {
        color: var(--ink-black);
    }
    .pinned {
        background: var(--paper-white);
    }
    .details {
        display: block;
        font-size: 10px;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
        color: var(--ink-black);
    }
}

footer {
    padding: 0 8px 4px 8px;
    font-size: 10px;
    text-align: center;
    line-height: 20px;
    background: var(--paper-white);
    color: var(--medium-grey);
    h1 + p {
        font-style: italic;
    }
    a:hover,
    a:active {
        text-decoration: underline;
        color: var(--ink-black);
    }
    p a,
    p a:link,
    p a:visited {
        text-decoration: underline;
    }

    .logo,
    .support {
        display: inline-block;
        position: absolute;
        bottom: 4px;
        left: 8px;
        opacity: .5;
    }
    .logo svg path {
        fill: currentColor;
    }
    .logo * + * {
        margin-left: 8px;
    }
    .support {
        right: 8px;
        left: auto;
    }
}

label {
    margin-right: .5ex;
    color: var(--medium-grey);
}
button {
    all: unset;

    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 18px;
    position: relative;
    margin: 0 .5ex 0 0;

    border: 1px solid var(--light-grey);
    border-radius: 3px;
    background: linear-gradient(var(--bright-white), var(--light-grey));
    color: var(--medium-grey);
    cursor: pointer;

    @media (prefers-color-scheme: dark) {
        background: linear-gradient(var(--light-grey), var(--bright-white));
    }

    path,
    rect {
        fill: currentColor;
    }

    &:hover {
        color: var(--ink-black);
    }
    &.selected {
        background: var(--bright-white);
        color: var(--ink-black);
        box-shadow: none;
    }
    &:not(.selected) > svg:not(:first-child),
    &.selected > svg:not(.selected) {
        display: none;
    }

    &:disabled {
        color: var(--paper-white);
        background: var(--light-grey);
    }

    &.text-button {
        width: auto;
        margin: 0;
        padding: 0 .5ex;
    }
}

select {
    all: unset;
    width: 9em;
    padding: 0 .5ex;
    border: 1px solid var(--light-grey);
    border-radius: 3px;
    background: var(--paper-white);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;

    option {
        background: var(--light-white);
        color: var(--ink-black);
    }
}

input[type='text'] {
    line-height: 12px;
}
input[type='text'],
input[type='number'] {
    all: unset;
    width: 4em;
    margin-left: .5ex;
    padding: 0 .5ex;
    border: 1px solid var(--light-grey);
    border-radius: 3px;
    background: var(--paper-white);
    text-align: left;
    transition: all .2s ease-in-out;
}
input[type='text']:hover,
input[type='text']:focus,
input[type='number']:hover,
input[type='number']:focus,
select:hover,
select:focus {
    border-color: var(--medium-grey);
    background: var(--paper-white);
}

pre,
textarea,
.CodeMirror {
    height: auto;
    font-family: monospace;
}
form {
    height: 100%;
    min-height: 100%;
    position: relative;
    z-index: 1;
}
.nav-button {
    all: unset;
    font-family: inherit;
    cursor: pointer;
}
label + .nav-button {
    margin-left: .5ex;
}

.CodeMirror {
    height: 100%;
    min-height: 100%;
    border: none;
    font-size: 100%;
    background: transparent;
    box-shadow: none !important;
    text-rendering: optimizeLegibility;

    /* https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors#attrvalue_3 */
    &[data-font|="monaspace"] {
        font-feature-settings: 'calt', 'ss01', 'ss02', 'ss03', 'ss04', 'ss05', 'ss06', 'ss07', 'ss08', 'ss09', 'liga';
    }

    .cm-comment {
        font-style: italic;
    }
}
.CodeMirror-gutters {
    background: transparent;
}
.CodeMirror-scroll {
    -webkit-overflow-scrolling: touch;
}

dialog {
    width: 40rem;
    max-width: calc(100% - 2rem);
    font-size: 1rem;
    border: 1px solid var(--light-grey);
    border-radius: 6px;
    background: var(--paper-white);
    color: var(--dark-grey);

    &::backdrop {
        background: var(--ink-black);
        opacity: .5;
        backdrop-filter: blur(10px);
    }

    h2 {
        font-size: 20px;
        font-weight: bold;
    }

    * + p {
        margin-top: 1em;
    }

    small {
        line-height: 14px;
    }

    button {
        position: absolute;
        top: 6px;
        right: 4px;
        color: inherit;
        svg path {
            fill: currentColor;
        }
    }

    a,
    a:link,
    a:visited {
        text-decoration: underline;
        color: var(--accent);
    }
}
body:has(dialog[open]) {
    .main-wrapper,
    .codemirror-wrapper {
        filter: blur(2px);
        transition: filter .5s ease-in-out;
    }
}

@media screen and (max-width: 56em) {
    body {
        display: block;
    }
    .main-wrapper,
    form {
        width: 100%;
        height: 50vh;
        min-height: 50vh;
        float: none;
    }
}
